package org.apache.servicecomb.samples.practise.houserush.sale.entity;

import lombok.Data;
import net.minidev.json.annotate.JsonIgnore;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "favorites")
@EntityListeners(AuditingEntityListener.class)
public class Favorite {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(name = "house_order_id", insertable = false, updatable = false)
    private int houseOrderId;
    private Integer customerId;

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date CreatedAt;
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date UpdatedAt;

    //房源订单收藏和房源订单是多对一的关系
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "house_order_id")
    @JsonIgnore
    private HouseOrder houseOrder;

    @Override
    public String toString() {
        return "Favorite{" +
                "id=" + id +
                ", houseOrderId=" + houseOrderId +
                ", customerId=" + customerId +
                ", CreatedAt=" + CreatedAt +
                ", UpdatedAt=" + UpdatedAt +
                ", houseOrder=" + houseOrder +
                '}';
    }
}
